'use strict'

const Service = require('egg').Service

class LeavewordService extends Service {
  // 获取留言(已登录)
  async getListAuth(user_id, data) {
    const { app } = this
    for (let index = 0; index < data.rows.length; index++) {
      // 留言id
      const leaveword_id = data.rows[index].id
      // 用户是否喜欢
      const result = await app.model.Feedback.findOne({ where: { leaveword_id, type: 1, user_id } })
      data.rows[index].is_like = Boolean(result)
    }
    return data
  }
}

module.exports = LeavewordService
